<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\model\RafflePrize;
use app\common\model\RaffleRecord;
use app\common\tool\Result;
use think\Response;

class Raffle extends Base
{
    public function index(): Response
    {
        $result = [
            'raffle_open' => $this->system['raffle_open'],
            'raffle_amount' => $this->system['raffle_amount'],
            'prize' => RafflePrize::order('id asc')->column('id,title,icon,amount,odds,position')
        ];

        return Result::success('success', $result);
    }

    public function submit(): Response
    {
        return Result::fastReturn(RaffleRecord::submit($this->user, $this->system));
    }

    public function record(): Response
    {
        $map = ['uid' => $this->user->id];

        return Result::fastReturn(RaffleRecord::getPageList($map, 'id,uid,title,icon,amount,create_time',
            $this->getPage(), $this->getLimit(), false));
    }
}